package org.openintents.droidcon.cloud.mvc;

import org.openintents.droidcon.cloud.model.Room;
import org.openintents.droidcon.cloud.model.Schedule;

public class RoomForm {

	private Room editRoom = null;
	private Schedule schedule = null;

	public RoomForm(Schedule schedule, Room editRoom) {
		if (editRoom != null) {
			this.editRoom = editRoom;
		}
		if (schedule != null) {
			this.schedule = schedule;
		}
	}

	public String display() {
		if (schedule != null) {
			String output = "<form action=\"/droidconcloud/schedule\" method=\"post\">"
					+ "<fieldset><legend>Room</legend>"
					+ "<label for=\"name\">Room name:</label> "
					+ "<input type=\"text\" name=\"name\" id=\"name\" value=\""
					+ (editRoom != null ? editRoom.getName() : "")
					+ "\" /><br/>"
					+ "<label for=\"alias\">Room alias:</label> "
					+ "<input type=\"text\" name=\"alias\" id=\"alias\" value=\""
					+ (editRoom != null ? editRoom.getAlias() : "")
					+ "\" />"
					+  "<input type=\"hidden\" name=\"id\" value=\""
							+ schedule.getId() + "\" />"							
					+ (editRoom != null ? "<input type=\"hidden\" name=\"roomId\" value=\""
							+ editRoom.getId().getId() + "\" />"
							: "")
					+ (editRoom == null ? "<input type=\"hidden\" name=\"action\" value=\"addRoom\" />"
							: "")
					+ (editRoom != null ? "<input type=\"hidden\" name=\"action\" value=\"editRoom\" />"
							: "")
					+ "<input type=\"submit\" value=\""
					+ (editRoom != null ? "edit" : "add")
					+ " room\" /> "
					+ "<input type=\"submit\" name=\"action\" value=\"reset\" />"
					+ "</fieldset>" + "</form>";
			return output;
		} else {
			return "";
		}
	}

}
